package com.le.tester.webpage.timeTaskTester;

import com.le.tester.common.Const;

import java.sql.Time;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Timer;
import java.util.TimerTask;

/**
 * 描述：时间定时器
 */
public class TimeTaskTester {

    private DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(Const.STANDARD_FORMAT);

    public static void main(String[] args) {

        new TimeTaskTester().f();
    }

    public void f() {
        Timer timer = new Timer();
        TimerTask timerTask = new TimerTask() {
            int count = 0;

            @Override
            public void run() {
                System.out.println("count is " + count);
                if (count < 10) {
                    System.out.println(LocalDateTime.now().format(dateTimeFormatter));
                    System.out.println("开始插入数据");
                } else {
                    System.out.println("取消任务");
                    System.out.println(LocalDateTime.now().format(dateTimeFormatter));
                    timer.cancel();
                }
                count++;
            }
        };
        timer.schedule(timerTask, 1000, 2 * 1000);

    }


}
